import { SELECT_DATE } from "../constants/redux"
import { zero } from '../utils/tools'

export interface DateType{
    start: string
    end: string
    list: string[]
}

const now = new Date()
const tomorrow = new Date(now.getTime()+(24*60*60*1000))
const start = `${now.getFullYear()}-${zero(now.getMonth()+1)}-${zero(now.getDate())}`
const end = `${tomorrow.getFullYear()}-${zero(tomorrow.getMonth()+1)}-${zero(tomorrow.getDate())}`
const init_state: DateType = { start, end, list: [] }

const selectDate = (state = init_state, action) => {
    switch(action.type){
        case SELECT_DATE:
            return {...state, ...action.selectDate}
        default:
            return state
    }
}
export default selectDate
